home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 3860 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.1 KB

  1. Path: news.itd.umich.edu!not-for-mail
  2. From: jlthomas@umd.umich.edu (Jeffrey L. Thomas)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Writing to a port
  5. Date: 31 Jan 1996 12:19:21 -0500
  6. Organization: Univerisity of Michigan - Dearborn
  7. Message-ID: <4eo8ap$3vk@null.umd.umich.edu>
  8. References: <22898@storm.LakeheadU.Ca>
  9. NNTP-Posting-Host: null.umd.umich.edu
  10. NNTP-Posting-User: jlthomas
  11. X-Newsreader: NN version 6.5.0 #3 (NOV)
  12.  
  13. romulus@lakeheadu.ca (Romulus the Almighty) writes:
  14.  
  15. >Help would be greatly appreciated with the following:
  16.  
  17. >I am attempting to make a cgi C program that will telnet to port 25 on
  18. >a server, take an argument to who the sender is, and take the rest of the
  19. >argument and send it to the recipient directly using sendmail on port 25            
  20. >of a server.  I use system(); to telnet over to the port and here is where
  21. >my problem is:  How do I send statements directly to the port such as
  22. >"HELO flash.lakeheadu.ca" and the other necessary statements...
  23.  
  24. >Thanx
  25.  
  26. >    John
  27.  
  28. you don't there is know way of comunicating with the system() fuction aside
  29. from the parameters you pass it.
  30.  
  31. here is what you want to do
  32.  
  33. void open25(host)
  34.     char host[];
  35. {
  36.     int pdc[2], pdp[2];
  37.  
  38.     if (pipe(pdc)<0 || pipe(pdp)<0) { perror("pipe"); exit(1); }
  39.  
  40.     if ((pid= fork())<0) { perror("fork"); exit(1); }
  41.  
  42.     if (pid==0) { /* I am Child */
  43.         dup2(pdc[0],0);
  44.         dup2(pdp[1],1);
  45.  
  46.         execl("/usr/ucb/telnet","telnet",host,"25");
  47.         perror("exec: telnet");
  48.         exit(1);
  49.     }
  50.  
  51.     /* I am Parent */
  52.  
  53.     dup2(pdc[1],1);
  54.     dup2(pdp[0],0);
  55. }
  56.  
  57. and in you main program
  58.  
  59. open25("mailhost"); /* or whatever machine */
  60.  
  61. printf("HELO flash.lakeheadu.ca"); /* blah, blah, blah */
  62. gets(line) /* getting the response back from the telnet */
  63.  
  64. and your off and running.
  65.  
  66. but you don't even want to do that what you really want to do is to learn
  67. all about sockets and to this with the socketing calls.
  68.  
  69.  
  70. Have a great day.
  71. Jeff
  72. -- 
  73. \|||/  _Spike_Man_      ____  | Jeffery L. Thomas  | "The important thing is
  74.  ^.^  The Internet's   /    \ | jlthomas@umich.edu | not to stop questioning.
  75.   v   first superhero  \ SM / | "This time it will | Curiosity has it own
  76. "more than a cute .sig" \__/  | surely run" - anon | reason for existing."
  77.